<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>登录系统</title>
    <link rel="stylesheet" href="layui/css/layui.css">
    <style>
        body {
            background: #f2f2f2;
        }

        .oa-container {
            /*background: white;*/
            position: absolute;
            width: 400px;
            height: 350px;
            top: 50%;
            left: 50%;
            padding: 20px;
            margin-left: -200px;
            margin-top: -175px;
        }

        #username, #password {
            text-align: center;
            font-size: 24px;
        }
    </style>
</head>
<body>
<div class="oa-container">
    <h1 style="text-align: center; margin-bottom: 20px">登录系统</h1>
    <form class="layui-form" id="form-login">
        <div class="layui-form-item">
            <input type="text" id="username" lay-verify="required" name="username" placeholder="请输入用户名"
                   autocomplete="off" class="layui-input">
        </div>
        <div class="layui-form-item">
            <input type="password" id="password" lay-verify="required" name="password" placeholder="请输入密码"
                   autocomplete="off" class="layui-input">
        </div>
        <div class="layui-form-item">
            <button class="layui-btn layui-btn-fluid" lay-submit lay-filter="login">登录</button>
        </div>
    </form>
</div>
<script src="./layui/layui.all.js"></script>
<script>
    // 表单提交事件
    layui.form.on("click(login)", function () {
console.log($("#form-login").serialize())
        //发送ajax请求进行登录校验
        layui.$.ajax({
            url: "/student/login",
            data: $("#form-login").serialize(), //提交表单数据
            type: "post",
            dataType: "json",  //返回的数据类型
            success: function (json) {
                console.log(json);
                if (json.state == 200) { //登录校验成功
                    alert("登录成功");
                    // location.href = "index.html";
                } else {
                    alert("登录失败"+json.message);
                }
            }
        })
    })
</script>
</body>
</html>